const express = require('express');
const jwt = require('jsonwebtoken');
const router = express.Router();

router.post('*', (req, res, next) => {
    if (req.url == '/mine/getInfo' || req.url == '/mine/changeName' || req.url == 'uploadImg/changeAvatar' || req.url == '/verify') {
        var token = req.body.token;
        var secret = req.body.userId;
        jwt.verify(token, secret, (err, decode) => {
            if (err) {
                res.send({ status: false, content: "token密钥已失效" });
            } else if (req.url == '/verify') {
                res.send({ status: true, content: "验证成功" });
            } else {
                next();
            }
        })
    } else {
        next();
    }
})

module.exports = router;